//
//  View2Demo.swift
//  firstProject
//
//  Created by 张彦辉 on 2017/3/21.
//  Copyright © 2017年 张彦辉. All rights reserved.
//

import UIKit
import SnapKit
import Alamofire
import SwiftyJSON


// MARK: --功能演示代码
extension View2Controller{
    //MARK: -网络请求
    func gotoNetwork() -> Void {
        let sheetController = UIAlertController(title: "网络请求", message: "", preferredStyle: .actionSheet)
        let action1 = UIAlertAction(title: "URLSession", style: .default) { (action) in
            let url = URL(string: URLs.urlStr)
            let session = URLSession.shared
            let task = session.dataTask(with: url!) { (data, response, error) in
                let json = JSON(data!)
                PublicUtil.alert(obj: self, title: "提示", msg: "返回json 中origin=\(json["origin"])")
            }
            task.resume()
        }
        sheetController.addAction(action1)
        let action2 = UIAlertAction(title: "Alamofire", style: .default) { (action) in
            
            Alamofire.request(URLs.urlStr2, method: .get, encoding: JSONEncoding.default, headers: nil).responseJSON(completionHandler: { (response) in
                let json = JSON(response.data!)
                PublicUtil.alert(obj: self, title: "提示", msg: "返回json 中id=\(json["id"])")
            })
        }
        sheetController.addAction(action2)
        self.present(sheetController, animated: true, completion: nil)
    }
    //MARK: -提示框
    func gotoAlert() -> Void {
        
        let sheetController = UIAlertController(title: "alert", message: "", preferredStyle: .actionSheet)
        let action1 = UIAlertAction(title: "alert", style: .default) { (action) in
            let alertCon = UIAlertController(title: "alert", message: "提示框", preferredStyle: .alert)
            let closeAction = UIAlertAction(title: "关闭", style: .cancel, handler: nil)
            alertCon.addAction(closeAction)
            self.present(alertCon, animated: true, completion: nil)
        }
        sheetController.addAction(action1)
        let action2 = UIAlertAction(title: "sheet", style: .default) { (action) in
            let sheetCon = UIAlertController(title: "sheet", message: "提示框", preferredStyle: .actionSheet)
            let closeAction = UIAlertAction(title: "关闭", style: .cancel, handler: nil)
            sheetCon.addAction(closeAction)

            self.present(sheetCon, animated: true, completion: nil)
        }
        sheetController.addAction(action2)
        self.present(sheetController, animated: true, completion: nil)
    }
    //MARK: -UICollectionView
    func gotoCollection() -> Void {
        self.navigationController?.pushViewController(UICollectionViewDemo(), animated: true)
    }
    func gotoWait() -> Void {
        self.navigationController?.pushViewController(UIActivityViewDemo(), animated: true)
    }
    //MARK: -分页控制器
    func gotoPageControl() -> Void {
        self.navigationController?.pushViewController(UIPageControlDemo(), animated: true)
    }
    
    //MARK: -进度条
    func gotoProgress() -> Void {
        self.navigationController?.pushViewController(UIProgressViewDemo(), animated: true)
    }
    //MARK: -查询条
    func gotoSearchBar() -> Void {
        self.navigationController?.pushViewController(UISearchBarDemo(), animated: true)
    }
    //MARK: -UIImageView
    func gotoImageView() -> Void {
        self.navigationController?.pushViewController(UIImageViewDemo(), animated: true)
    }
    //MARK: -UISlider
    func gotoSlider() -> Void {
        self.navigationController?.pushViewController(UISliderDemo(), animated: true)
    }
    //MARK: -UIPickerView
    func gotoPicker() -> Void {
        self.navigationController?.pushViewController(UIPickerViewDemo(), animated: true)
    }
    //MARK: -UIScrollView
    func gotoScrollView() -> Void {
        self.navigationController?.pushViewController(UIScrollViewDemo(), animated: true)
    }
    //MARK: -UIScrollView
    func gotoStepper() -> Void {
        self.navigationController?.pushViewController(UIStepperDemo(), animated: true)
    }
    func gotoSwitch() -> Void {
        self.navigationController?.pushViewController(UISwitchDemo(), animated: true)
    }
    
    func gotoAnimateView() -> Void {
        self.navigationController?.pushViewController(UIAnimateDemo(), animated: true)
    }
    
    func gotoWebView() -> Void {
        self.navigationController?.pushViewController(UIWebWiewDemo(), animated: true)
    }
    func gotoShaHe() -> Void {
        self.navigationController?.pushViewController(ShaHeDemo(), animated: true)
    }
    func gotoDrawCircle() -> Void {
        self.navigationController?.pushViewController(DrawCircleDemo(), animated: true)
    }
    func gotoViewAnimate() -> Void {
        self.navigationController?.pushViewController(UIViewAnimateDemo(), animated: true)
    }
    func gotoFileManager() -> Void {
        self.navigationController?.pushViewController(FileManagerDemo(), animated: true)
    }
    func gotoTextFile() -> Void {
        self.navigationController?.pushViewController(TextFileDemo(), animated: true)
    }
    func gotoPlist() -> Void {
        self.navigationController?.pushViewController(PlistDemo(), animated: true)
    }
    func gotoUserDefault() -> Void {
        self.navigationController?.pushViewController(UserDefaultDemo(), animated: true)
    }
    func gotoArchive() -> Void {
        self.navigationController?.pushViewController(ArchiveDemo(), animated: true)
    }
    
    
}
